//
//  MainTableViewController.m
//  FKGCDTestDemo
//
//  Created by 云眼科技 on 16/7/29.
//  Copyright © 2016年 CloudEyes. All rights reserved.
//

#import "MainTableViewController.h"

#import "GCDSyncViewController.h"
#import "GCDAsyncViewController.h"

@interface MainTableViewController ()
@property (nonatomic, strong) NSMutableArray <UIViewController *> *dataArray;
@end


static NSString *const mainCellIdentifier = @"mainCellIdentifier";

@implementation MainTableViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"FKGCD";
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:mainCellIdentifier];
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:mainCellIdentifier forIndexPath:indexPath];
    cell.textLabel.text = self.dataArray[indexPath.row].title;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.navigationController pushViewController:self.dataArray[indexPath.row] animated:YES];
}


-(NSMutableArray<UIViewController *> *)dataArray{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc] init];
        GCDAsyncViewController *asyncVC = [[GCDAsyncViewController alloc] init];
        GCDSyncViewController  *syncVC = [[GCDSyncViewController alloc] init];
        asyncVC.title = @"GCD-Async";
        syncVC.title = @"GCD-Sync";
        [_dataArray addObject:asyncVC];
        [_dataArray addObject:syncVC];
    }
    return _dataArray;
}




@end
